package tuples;

import list.FixedList;

/**
 *
 * @author Shimu
 * @date 9-Oct-2012
 */
public class ImmutableList<T> extends FixedList<T> {

    private T[] ELEMENTS;

    public ImmutableList(T... elements) {
        super(elements.length);
        this.ELEMENTS = (T[]) new Object[elements.length];
        System.arraycopy(elements, 0, this.ELEMENTS, 0, elements.length);
    }

    @Override
    public T get(int index) {
        return this.ELEMENTS[index];
    }

    @Override
    public T set(int index, T element) {
        throw new UnsupportedOperationException(
                "Cannot set the elements of an immutable list!");
    }

    @Override
    public FixedList<T> subList(int fromIndex, int toIndex) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
